﻿using CSRedis;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartConference.Api.Applocations.IServices;
using SmartConference.Api.DTO;
using SmartConference.Domain;
using SmartConference.ErrorCode;
using SmartConference.Infrastructure.Implements;
using SmartConference.Infrastructure.Interfaces;
using System.ComponentModel;

namespace SmartConference.Api.Controllers
{
    /// <summary>
    /// 部门管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiExplorerSettings(GroupName ="部门管理")]
    [ApiController]
    public class DepartmentController : ControllerBase
    {
        private readonly IDepartmentServices departmentServices;
        private readonly CSRedisClient redis;

        public DepartmentController(IDepartmentServices departmentServices,CSRedisClient redis)
        {
            this.departmentServices = departmentServices;
            this.redis = redis;
        }

        /// <summary>
        /// 获取部门信息
        /// </summary>
        /// <param name="DepartmentName">部门名称</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页容量</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<IList<TreeDept>>> ShowDepartment(string? DepartmentName, int parentid)
        {
            try
            {
                return await departmentServices.ShowDepartment(DepartmentName,parentid);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 新增部门
        /// </summary>
        /// <param name="departmentInfoDTO">部门实体</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddDept(AddDepartmentDTO departmentInfoDTO)
        {
            try
            {
                return await departmentServices.AddDept(departmentInfoDTO);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改部门
        /// </summary>
        /// <param name="departmentInfo">部门实体</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateDept(DepartmentInfo departmentInfo)
        {
            try
            {
                return await departmentServices.UpdateDept(departmentInfo);
            }
            catch (Exception)
            {

                throw;
            }
        }


        /// <summary>
        /// 修改部门状态
        /// </summary>
        /// <param name="DepartmentId">部门Id</param>
        /// <param name="status">状态</param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateDeptStatus(int DepartmentId, int status)
        {
            try
            {
                return await departmentServices.UpdateDeptStatus(DepartmentId, status);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="DepartmentId">部门Id</param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> DeleteDept(int DepartmentId)
        {
            try
            {
                return await departmentServices.DeleteDept(DepartmentId);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 级联获取部门信息
        /// </summary>
        /// <param name="ParentId">父级Id</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ItemMenu>>> GetDeptByParentId(int ParentId)
        {
            try
            {
                return await departmentServices.GetDeptByParentId(ParentId);
            }
            catch (Exception)
            {

                throw;
            }
        }

        
    }

}
